<?php

declare (strict_types=1);
namespace App\Model;

/**
 * @property int $id
 * @property string $code
 * @property string $label
 * @property int $label_type
 * @property int $trial
 * @property string $price
 * @property int $unit
 * @property int $quantity
 * @property string $description
 * @property string $title
 * @property int $status
 * @property int $sort
 * @property int $lang
 */
class SubOption extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'sub_option';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'code', 'label', 'label_type', 'trial', 'price', 'unit', 'quantity', 'description', 'title', 'status', 'sort','lang'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'label_type' => 'integer', 'trial' => 'integer', 'unit' => 'integer', 'quantity' => 'integer', 'status' => 'integer', 'sort' => 'integer'];

    /**
     * 计算到期时间
     * @param $unit
     * @param $quantity
     * @return false|string
     */
    public static function countRenewDay($unit,$quantity){

        $startTime = date('Y-m-d H:i:s');
        $str = '';

        switch ($unit){
            case 1:
                $str = $startTime . ' +' . $quantity . ' week';
                break;
            case 2:
                $str = $startTime . ' +' . $quantity . ' month';
                break;
            case 3:
                $str = $startTime . ' +' . $quantity . ' year';
                break;

        }
        if (empty($str)){
            return false;
        }else{
            return date('Y-m-d H:i:s', strtotime($str));
        }

    }

}
